<?php
class Administration_Form_Users extends Jnd_Form
{

    public function __construct( $decorateur = "Formulairejnd", $options = null )
    {
        parent::__construct($decorateur, $options);
        $this->setElementDecorators(array(
            "$decorateur"
        ), array(
            'avatar'
        ), false);
    }

    public function init()
    {
        
        //
        // Field id
        $field = new Zend_Form_Element_Text("id");
        $field->setLabel('Id');
        $field->setAttribs(array(
            'readonly' => 'readonly', 
            'class' => 'readonly'
        ));
        $field->setFilters(array(
            'Digits'
        ));
        $fields[] = $field;
        
        //
        //  Field Lastname
        $field = new Zend_Form_Element_Text("lastname");
        $field->setLabel(_('Lastname'));
        $field->setRequired(true);
        $fields[] = $field;
        
        //
        //  Field Firstname
        $field = new Zend_Form_Element_Text("firstname");
        $field->setLabel(_('Firstname'));
        $field->setRequired(true);
        $fields[] = $field;
        
        //
        //  Field Username
        $field = new Zend_Form_Element_Text("username");
        $field->setLabel(_('Username'));
        $field->setRequired(true);
        $fields[] = $field;
        
        //
        //	Field Admin
        $field = new Zend_Form_Element_Radio("admin");
        $field->setLabel(__("Admin"));
        $field->setMultiOptions(array(
        	"0" => __("No"),
        	"1" => __("Yes"),
        ));
        $fields[] = $field;
        
        //
        //  Field Password
        $field = new Zend_Form_Element_Password("password");
        $field->setLabel(_('Password'));
        $fields[] = $field;
        
        //
        //  Field mail
        $field = new Zend_Form_Element_Text("email");
        $field->setLabel(_('Mail'));
        $fields[] = $field;
        
        //
        //  Field creationUser
        $field = new Zend_Form_Element_Text("creationUser");
        $field->setLabel(_('Created by'));
        $field->setAttribs(array(
            "readonly" => "readonly", 
            "class" => "readonly"
        ));
        $fields[] = $field;
        
        //
        //	Field crationDate
        $field = new Zend_Form_Element_Text("creationDate");
        $field->setLabel(__('Created'));
        $field->setAttribs(array(
            "readonly" => "readonly", 
            "class" => "readonly"
        ));
        $field->setValue(date(Jnd_Global_Constantes::FORMAT_DATE_WEB_LONG));
        $fields[] = $field;
        
        if ($this->_decorator != "Voir") {
            //
            //  CField Picture
            $element = new Zend_Form_Element_File('avatar');
            $element->setLabel(__('Choose a picture'))->setDestination(dirname(APPLICATION_PATH) . "/public/images/users/avatars");
            // ensure only 1 file
            $element->addValidator('Count', false, 1);
            // limit to 100K
            $element->addValidator('Size', false, 102400);
            // only JPEG, PNG, and GIFs
            $element->addValidator('Extension', false, 'jpg,jpeg,png,gif');
        
     //        $element->setDecorators(array("Formulaireddb"));
        } else {
            $element = new Zend_Form_Element_Image("avatar");
        }
        $fields[] = $element;
        
        $this->addElements($fields);
        
        $this->setName("users");
    }

}